/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InternalFrame_ubahStatusStaff.java
 *
 * Created on Nov 24, 2011, 10:25:26 PM
 */
package Boundaries;

import Controller.Change_Controller;
import Entities.Kendaraan;
import Entities.Sewa;
import TableModel.Kendaraan_List;
import TableModel.Kendaraan_TableModel;
import TableModel.Kendaraan_TanggalKembali_Model;
import TableModel.Persewaan_List;
import TableModel.Persewaan_Rekap_TableModel;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import sun.java2d.pipe.SpanShapeRenderer.Simple;

/**
 *
 * @author Tea-Nose
 */
public class InternalFrame_ubahStatusStaff extends javax.swing.JInternalFrame {

    /** Creates new form InternalFrame_ubahStatusStaff */
    public InternalFrame_ubahStatusStaff() {
        try {
            initComponents();

            List<Sewa> sewas = Persewaan_List.getKendaraanList().getAllPersewaan();
            Persewaan_Rekap_TableModel persewaan_Rekap_TableModel = new Persewaan_Rekap_TableModel(sewas);
            jTable1.setModel(persewaan_Rekap_TableModel);

        } catch (SQLException ex) {
            Logger.getLogger(InternalFrame_ubahStatusStaff.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panel_PanelUbahStatusStaff = new javax.swing.JPanel();
        label_Denda = new javax.swing.JLabel();
        label_MerkKendaraanLabel = new javax.swing.JLabel();
        tf_tanggalSewa = new javax.swing.JTextField();
        tf_NoSewa = new javax.swing.JTextField();
        label_NoPolisiKendaraan = new javax.swing.JLabel();
        tf_noPolisiKendaraan = new javax.swing.JTextField();
        label_TanggalKembali = new javax.swing.JLabel();
        cmbBox_statusBaru = new javax.swing.JComboBox();
        button_cancel = new javax.swing.JButton();
        button_OK = new javax.swing.JButton();
        label_StatusTerakhir = new javax.swing.JLabel();
        tf_Denda = new javax.swing.JTextField();
        label_Date = new javax.swing.JLabel();
        label_StatusBaru1 = new javax.swing.JLabel();
        tf_tanggalKembali = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        tf_cariNoFaktur = new javax.swing.JTextField();
        label_TanggalSekarang = new javax.swing.JLabel();
        tf_tanggalSekarang = new javax.swing.JTextField();
        label_Denda1 = new javax.swing.JLabel();
        tf_BiayaSewa = new javax.swing.JTextField();
        label_Denda2 = new javax.swing.JLabel();
        tf_TotalBayar = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();

        setPreferredSize(new java.awt.Dimension(1010, 480));
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        panel_PanelUbahStatusStaff.setBackground(new java.awt.Color(204, 204, 255));
        panel_PanelUbahStatusStaff.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        label_Denda.setText("Denda");
        panel_PanelUbahStatusStaff.add(label_Denda, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 40, -1, -1));

        label_MerkKendaraanLabel.setText("No Sewa");
        panel_PanelUbahStatusStaff.add(label_MerkKendaraanLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, -1));

        tf_tanggalSewa.setEditable(false);
        tf_tanggalSewa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_tanggalSewaActionPerformed(evt);
            }
        });
        panel_PanelUbahStatusStaff.add(tf_tanggalSewa, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 70, 100, -1));

        tf_NoSewa.setEditable(false);
        tf_NoSewa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_NoSewaActionPerformed(evt);
            }
        });
        panel_PanelUbahStatusStaff.add(tf_NoSewa, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 10, 90, -1));

        label_NoPolisiKendaraan.setText("No Polisi Kendaraan");
        panel_PanelUbahStatusStaff.add(label_NoPolisiKendaraan, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, -1, -1));

        tf_noPolisiKendaraan.setEditable(false);
        tf_noPolisiKendaraan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_noPolisiKendaraanActionPerformed(evt);
            }
        });
        panel_PanelUbahStatusStaff.add(tf_noPolisiKendaraan, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 40, 70, -1));

        label_TanggalKembali.setText("Tanggal Kembali");
        panel_PanelUbahStatusStaff.add(label_TanggalKembali, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 100, -1, -1));

        cmbBox_statusBaru.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "SIAP SEWA", "RUSAK" }));
        cmbBox_statusBaru.setEnabled(false);
        cmbBox_statusBaru.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbBox_statusBaruActionPerformed(evt);
            }
        });
        panel_PanelUbahStatusStaff.add(cmbBox_statusBaru, new org.netbeans.lib.awtextra.AbsoluteConstraints(710, 10, 90, -1));

        button_cancel.setText("Cancel");
        button_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button_cancelActionPerformed(evt);
            }
        });
        panel_PanelUbahStatusStaff.add(button_cancel, new org.netbeans.lib.awtextra.AbsoluteConstraints(730, 60, 70, -1));

        button_OK.setText("OK");
        button_OK.setEnabled(false);
        button_OK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button_OKActionPerformed(evt);
            }
        });
        panel_PanelUbahStatusStaff.add(button_OK, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 60, 70, -1));

        label_StatusTerakhir.setText("Tanggal Sewa");
        panel_PanelUbahStatusStaff.add(label_StatusTerakhir, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 70, -1, -1));

        tf_Denda.setEditable(false);
        tf_Denda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_DendaActionPerformed(evt);
            }
        });
        panel_PanelUbahStatusStaff.add(tf_Denda, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 40, 90, -1));

        label_Date.setText("jLabel1");
        panel_PanelUbahStatusStaff.add(label_Date, new org.netbeans.lib.awtextra.AbsoluteConstraints(930, 10, -1, -1));

        label_StatusBaru1.setText("Status Baru");
        panel_PanelUbahStatusStaff.add(label_StatusBaru1, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 10, -1, -1));

        tf_tanggalKembali.setEditable(false);
        tf_tanggalKembali.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_tanggalKembaliActionPerformed(evt);
            }
        });
        panel_PanelUbahStatusStaff.add(tf_tanggalKembali, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 100, 100, -1));

        jPanel1.setBackground(new java.awt.Color(204, 204, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Data Sewa", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "No Faktur", "Nama Penyewa", "Alamat Penyewa", "No Telp Penyewa", "Tanggal Sewa", "Uang Sewa", "Tanggal Kembali", "Uang Denda", "No Polisi", "Keterlambatan"
            }
        ));
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jLabel2.setText("Cari No Faktur");

        tf_cariNoFaktur.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_cariNoFakturActionPerformed(evt);
            }
        });
        tf_cariNoFaktur.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tf_cariNoFakturKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 950, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(tf_cariNoFaktur, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(tf_cariNoFaktur, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        panel_PanelUbahStatusStaff.add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 150, 970, 180));

        label_TanggalSekarang.setText("Tanggal Sekarang");
        panel_PanelUbahStatusStaff.add(label_TanggalSekarang, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 130, -1, -1));

        tf_tanggalSekarang.setEditable(false);
        tf_tanggalSekarang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_tanggalSekarangActionPerformed(evt);
            }
        });
        panel_PanelUbahStatusStaff.add(tf_tanggalSekarang, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 130, 100, -1));

        label_Denda1.setText("Biaya Sewa");
        panel_PanelUbahStatusStaff.add(label_Denda1, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 10, -1, -1));

        tf_BiayaSewa.setEditable(false);
        tf_BiayaSewa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_BiayaSewaActionPerformed(evt);
            }
        });
        panel_PanelUbahStatusStaff.add(tf_BiayaSewa, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 10, 90, -1));

        label_Denda2.setText("Total Bayar");
        panel_PanelUbahStatusStaff.add(label_Denda2, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 80, -1, -1));

        tf_TotalBayar.setEditable(false);
        tf_TotalBayar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_TotalBayarActionPerformed(evt);
            }
        });
        panel_PanelUbahStatusStaff.add(tf_TotalBayar, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 80, 90, -1));
        panel_PanelUbahStatusStaff.add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 70, 190, -1));

        getContentPane().add(panel_PanelUbahStatusStaff, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 100, 1010, 360));

        jLabel1.setBackground(new java.awt.Color(255, 255, 255));
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Boundaries/Kembali Sewa.jpg"))); // NOI18N
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 1000, 100));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(950, 0, -1, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void tf_tanggalSewaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_tanggalSewaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_tanggalSewaActionPerformed

    private void tf_NoSewaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_NoSewaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_NoSewaActionPerformed

    private void tf_noPolisiKendaraanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_noPolisiKendaraanActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_noPolisiKendaraanActionPerformed

    private void tf_DendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_DendaActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_tf_DendaActionPerformed

    private void tf_tanggalKembaliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_tanggalKembaliActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_tanggalKembaliActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        // TODO add your handling code here:

        Change_Controller chng_Con = new Change_Controller();
        chng_Con.tableSewaClicked(this);

    }//GEN-LAST:event_jTable1MouseClicked

    private void tf_tanggalSekarangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_tanggalSekarangActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_tanggalSekarangActionPerformed

    private void tf_BiayaSewaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_BiayaSewaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_BiayaSewaActionPerformed

    private void tf_TotalBayarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_TotalBayarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_TotalBayarActionPerformed

    private void cmbBox_statusBaruActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbBox_statusBaruActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cmbBox_statusBaruActionPerformed

    private void button_OKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button_OKActionPerformed
        try {
            Kendaraan kend = new Kendaraan();
            String cek = kend.cekStatusKendaraan(tf_noPolisiKendaraan.getText());

            if (cek.matches("SIAP SEWA")) {
                JOptionPane.showMessageDialog(null, "Kendaraan sudah dikembalikan");
            } else {
                Change_Controller chng_Con = new Change_Controller();
                chng_Con.okButtonClicked(this);
                
            }
        } catch (SQLException ex) {
            Logger.getLogger(InternalFrame_ubahStatusStaff.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_button_OKActionPerformed

    private void tf_cariNoFakturKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_cariNoFakturKeyReleased
        try {
            // TODO add your handling code here:
            List<Sewa> sewas = Persewaan_List.getKendaraanList().getCariPersewaan(tf_cariNoFaktur.getText().toUpperCase());
            Persewaan_Rekap_TableModel persewaan_Rekap_TableModel = new Persewaan_Rekap_TableModel(sewas);
            jTable1.setModel(persewaan_Rekap_TableModel);
        } catch (SQLException ex) {
            Logger.getLogger(InternalFrame_ubahStatusStaff.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_tf_cariNoFakturKeyReleased

    private void tf_cariNoFakturActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_cariNoFakturActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_cariNoFakturActionPerformed

    private void button_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button_cancelActionPerformed
        // TODO add your handling code here:
        tf_NoSewa.setText("");
        tf_TotalBayar.setText("");
        tf_tanggalSewa.setText("");
        tf_tanggalSekarang.setText("");
        tf_tanggalKembali.setText("");
        tf_noPolisiKendaraan.setText("");
        tf_BiayaSewa.setText("");
        tf_Denda.setText("");
        tf_cariNoFaktur.setText("");
    }//GEN-LAST:event_button_cancelActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton button_OK;
    private javax.swing.JButton button_cancel;
    public javax.swing.JComboBox cmbBox_statusBaru;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    public javax.swing.JTable jTable1;
    private javax.swing.JLabel label_Date;
    private javax.swing.JLabel label_Denda;
    private javax.swing.JLabel label_Denda1;
    private javax.swing.JLabel label_Denda2;
    private javax.swing.JLabel label_MerkKendaraanLabel;
    private javax.swing.JLabel label_NoPolisiKendaraan;
    private javax.swing.JLabel label_StatusBaru1;
    private javax.swing.JLabel label_StatusTerakhir;
    private javax.swing.JLabel label_TanggalKembali;
    private javax.swing.JLabel label_TanggalSekarang;
    private javax.swing.JPanel panel_PanelUbahStatusStaff;
    public javax.swing.JTextField tf_BiayaSewa;
    public javax.swing.JTextField tf_Denda;
    public javax.swing.JTextField tf_NoSewa;
    public javax.swing.JTextField tf_TotalBayar;
    public javax.swing.JTextField tf_cariNoFaktur;
    public javax.swing.JTextField tf_noPolisiKendaraan;
    public javax.swing.JTextField tf_tanggalKembali;
    public javax.swing.JTextField tf_tanggalSekarang;
    public javax.swing.JTextField tf_tanggalSewa;
    // End of variables declaration//GEN-END:variables
}
